package com.liy.framework.common.office.pdf;

import org.apache.pdfbox.multipdf.*;
import java.io.*;
import org.slf4j.*;

public class PdfUtil
{
    protected static Logger log;
    
    public static void mergePDF(final String destFilePath, final String[] fileListPath) throws IOException {
        PdfUtil.log.info("\u5f00\u59cb\u5408\u5e76PDF\u6587\u4ef6\uff1a" + destFilePath);
        final long start = System.currentTimeMillis();
        final PDFMergerUtility mergePdf = new PDFMergerUtility();
        for (final String path : fileListPath) {
            mergePdf.addSource(path);
        }
        mergePdf.setDestinationFileName(destFilePath);
        mergePdf.mergeDocuments();
        final long end = System.currentTimeMillis();
        PdfUtil.log.info("\u5f00\u59cb\u5408\u5e76PDF\u6587\u4ef6\u5b8c\u6210\uff0c\u7528\u65f6\uff1a" + (end - start) + "ms");
    }
    
    public static void main(final String[] args) {
        final String[] fileListPath = { "H:\\D\u8fbe\u5b9e\u667a\u80fd\\\u62a5\u9500\\\u53d1\u7968\\2019-04\\8f7af886325c7a69a4b0ea1e2f521ce1.pdf", "H:\\D\u8fbe\u5b9e\u667a\u80fd\\\u62a5\u9500\\\u53d1\u7968\\2019-04\\044001800311-74183844.pdf", "H:\\D\u8fbe\u5b9e\u667a\u80fd\\\u62a5\u9500\\\u53d1\u7968\\2019-04\\04403170011119080234.pdf", "H:\\D\u8fbe\u5b9e\u667a\u80fd\\\u62a5\u9500\\\u53d1\u7968\\2019-04\\04403180021112515031.pdf", "H:\\D\u8fbe\u5b9e\u667a\u80fd\\\u62a5\u9500\\\u53d1\u7968\\2019-04\\04403190011123483041.pdf", "H:\\D\u8fbe\u5b9e\u667a\u80fd\\\u62a5\u9500\\\u53d1\u7968\\2019-04\\04403190011123483712.pdf", "H:\\D\u8fbe\u5b9e\u667a\u80fd\\\u62a5\u9500\\\u53d1\u7968\\2019-04\\c8ad6b3bbb8bd9e478c386f9993dba1f.pdf", "H:\\D\u8fbe\u5b9e\u667a\u80fd\\\u62a5\u9500\\\u53d1\u7968\\2019-04\\1.pdf", "H:\\D\u8fbe\u5b9e\u667a\u80fd\\\u62a5\u9500\\\u53d1\u7968\\2019-04\\2.pdf" };
        try {
            mergePDF("H:\\D\u8fbe\u5b9e\u667a\u80fd\\\u62a5\u9500\\\u53d1\u7968\\2019-04\\\u53d1\u7968.pdf", fileListPath);
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    static {
        PdfUtil.log = LoggerFactory.getLogger((Class)PdfUtil.class);
    }
}
